<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//加密用户user_id
function encrypt_user_id($id){
    return intval(2016000+$id);
}

//解密用户user_id
function decrypt_user_id($en_id){
    return intval($en_id - 2016000);
}


//加密文章id
function encrypt_article_id($id){
    return intval(21614+$id);
}

//解密文章id
function decrypt_article_id($en_id){
    return intval($en_id - 21614);
}

//加密文章评论id
function encrypt_comment_id($id){
    return intval(112514+$id);
}

//解密文章评论id
function decrypt_comment_id($en_id){
    return intval($en_id - 112514);
}

//加密问题id
function encrypt_wenda_id($id){
    return intval(24154+$id);
}

//解密问题id
function decrypt_wenda_id($en_id){
    return intval($en_id - 24154);
}

//加密答案id
function encrypt_answer_id($id){
    return intval(37514+$id);
}

//解密答案id
function decrypt_answer_id($en_id){
    return intval($en_id - 37514);
}

//加密答案评论id
function encrypt_answer_reply_id($id){
    return intval(12614+$id);
}

//解密答案评论id
function decrypt_answer_reply_id($en_id){
    return intval($en_id - 12614);
}

//加密答案评论id
function encrypt_lottery_id($id){
    return intval(12614+$id);
}

//解密答案评论id
function decrypt_lottery_id($en_id){
    return intval($en_id - 12614);
}

//加密答案评论id
function encrypt_lottery_record_id($id){
    return intval(12414+$id);
}

//解密答案评论id
function decrypt_lottery_record_id($en_id){
    return intval($en_id - 12414);
}
//加息编号
function encrypt_interests_id($id){
    return intval(24154+$id);
}
function decrypt_interests_id($id){
    return intval($id - 24154);
}
//加密视频id
function encrypt_video_id($id){
    return intval(324+$id);
}

//解密视频id
function decrypt_video_id($en_id){
    return intval($en_id - 324);
}

/**
 * 插入站内信通知
 * @param array $data 消息数据
 * @param interger $type 消息类型
 */
function insert_award_notice($data,$type){
    $ci = &get_instance();
    $db = $ci->db;
    if(!$data){
        return;
    }
    $db->insert("tan_users_award_notice",$data); 
    $insert_id = $db->insert_id();
    
    //导入
    $ci->load->library('my_getui');
    //推送消息
    $push = array();
    $push['type'] = $type;
    $push['title'] = $data['title'];
    $push['content'] = "您收到一条".$data['title'];
    $push['message_id'] = $insert_id;
    $Push = new My_getui();
    return $Push->pushMessageToSingle(encrypt_user_id($data['user_id']),$push);
}
/**
 * 推送消息，所有用户
 * @param array $data 消息数据
 * @param interger $type 消息类型
 * @param char $target_app 目标平台
 */
function insert_push_to_app($data,$type,$target_app){
    $ci = &get_instance();
    $target_app = $target_app ? $target_app : "tan66";
    //导入
    if($target_app == "tan66"){
        $ci->load->library('my_getui');
        $Push = new My_getui();
    }elseif($target_app == "liuliuqianbao"){
        $ci->load->library('my_getui1');
        $Push = new My_getui1();
    }else{
        //其他
    }
    //推送消息
    $push = array();
    $push['type'] = $type;
    $push['title'] = $data['title'];
    $push['content'] = $data['content'];
    $push['message_id'] = $data['message_id'];
    return $Push->pushMessageToApp($push);
}
/**
 * 推送消息，指定用户
 * @param array $usersAliasList 指定加密后的用户id数组，
 * @param array $data 消息数据
 * @param interger $type 消息类型
 * @param char $target_app 目标平台
 */
function insert_push_to_list($usersAliasList,$data,$type,$target_app){
    $ci = &get_instance();
    $target_app = $target_app ? $target_app : "tan66";
    if($target_app == "tan66"){
        $ci->load->library('my_getui');
        $Push = new My_getui();
    }elseif($target_app == "liuliuqianbao"){
        $ci->load->library('my_getui1');
        $Push = new My_getui1();
    }else{
        //其他
    }
    //推送消息
    $push = array();
    $push['type'] = $type;
    $push['title'] = $data['title'];
    $push['content'] = $data['content'];
    $push['message_id'] = $data['message_id'];
    return $Push->pushMessageToList($usersAliasList,$push);
}
